package com.atguigu.day02;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Example9 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env
                .fromElements(1,2,3,4,5,6,7,8,9,10,11,12).setParallelism(1)
                // 在idea中执行时，默认并行度是cpu的核数
                .print("test: ");

        // 将数据广播到下游的所有任务插槽
        env
                .fromElements(1,2,3,4).setParallelism(1)
                .broadcast()
                .print("broadcast: ").setParallelism(4);

        // 随机分配
        env
                .fromElements(1,2,3,4).setParallelism(1)
                .shuffle()
                .print("随机发送：").setParallelism(2);

        // round-robin
        // 轮询，平均分配
        env
                .fromElements(1,2,3,4).setParallelism(1)
                .rebalance()
                .print("平均分配：").setParallelism(2);

        // 将所有数据发送到下游算子的第一个任务插槽
        env
                .fromElements(1,2,3,4).setParallelism(1)
                .global()
                .print("global: ").setParallelism(4);

        env.execute();
    }
}
